package com.quantdo.apex.elasticjob.boot;

import com.dangdang.ddframe.job.api.ShardingContext;
import com.dangdang.ddframe.job.api.simple.SimpleJob;
import com.quantdo.apex.elasticjob.util.SpringContextUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

/**
 * @author chenkuan
 * @version v1.0
 * @desc Job调度处理分发
 * @date 2019/12/11 011 10:32
 */
@Service
public class SimpleJobHandle implements SimpleJob {

	private Logger logger = LoggerFactory.getLogger(getClass());

	@Override
	public void execute(ShardingContext context) {
		logger.debug("任务名:{}, 总片数:{}, 当前分片序列号:{}, 运行参数:{}", context.getJobName(), context.getShardingTotalCount(), context.getShardingItem(), context.getJobParameter());
		Job job = (Job) SpringContextUtil.getBean(context.getJobName());
		job.handle(context);
	}
}
